<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改密码 - AI面试系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <div class="container">
        <a class="navbar-brand" href="#">AI面试系统 - 用户管理</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <span class="nav-link">欢迎，[[${#authentication?.principal?.username ?: '管理员'}]]</span>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/admin/users}">用户管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/interview}">返回系统</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/logout}">退出登录</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-8 col-lg-6">
            <div class="card shadow">
                <div class="card-header bg-warning text-dark">
                    <h4 class="mb-0"><i class="bi bi-key"></i> 修改密码</h4>
                </div>
                <div class="card-body">
                    <!-- 用户信息 -->
                    <div class="alert alert-info">
                        <h6><i class="bi bi-person"></i> 用户信息</h6>
                        <p class="mb-0">
                            <strong>用户名：</strong> [[${user.username}]]<br>
                            <strong>全名：</strong> [[${user.fullName}]]<br>
                            <strong>邮箱：</strong> [[${user.email}]]
                        </p>
                    </div>

                    <!-- 错误消息 -->
                    <div th:if="${errorMessage}" class="alert alert-danger">
                        [[${errorMessage}]]
                    </div>

                    <form th:action="@{/admin/users/change-password/{id}(id=${user.id})}" method="post">
                        <div class="mb-3">
                            <label for="newPassword" class="form-label">新密码 <span class="text-danger">*</span></label>
                            <input type="password" class="form-control" id="newPassword" name="newPassword" required>
                            <div class="form-text">密码长度至少6位</div>
                        </div>

                        <div class="mb-3">
                            <label for="confirmPassword" class="form-label">确认新密码 <span class="text-danger">*</span></label>
                            <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" required>
                        </div>

                        <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                            <a th:href="@{/admin/users}" class="btn btn-secondary me-md-2">取消</a>
                            <button type="submit" class="btn btn-warning">修改密码</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script>
    // 密码确认验证
    document.getElementById('confirmPassword').addEventListener('input', function() {
        const password = document.getElementById('newPassword').value;
        const confirmPassword = this.value;
        
        if (password !== confirmPassword) {
            this.setCustomValidity('密码不匹配');
        } else {
            this.setCustomValidity('');
        }
    });

    document.getElementById('newPassword').addEventListener('input', function() {
        const confirmPassword = document.getElementById('confirmPassword');
        if (confirmPassword.value) {
            confirmPassword.dispatchEvent(new Event('input'));
        }
    });
</script>
</body>
</html>
